app.controller('linePreOrderController', ['$scope', 'ajax', 'linePreOrderService', 'Flash','$state',function ($scope, ajax, linePreOrderService,Flash,$state) {

        // 预订单列表列表
        function list(page) {
            linePreOrderService.list({
                orderStatus:1,
                currentPage: page,
                pageSize: 10,
                purchaseStatus:0,

            }).then(function (result) {
                console.log(result)
                $scope.data = result

            })
        }

        list(1);

        //分页
        $scope.pageChanged = function (e) {
            list(e);
        };

        $scope.genernate = function () {


                ajax.get({
                    url: '/back/purchaseOrder/genernate',
                    debug: true
                }).then(function (result) {

                    Flash.create('success', '生成成功', 'custom-class');
                    $state.go('admin.linePreOrder',null,{
                        reload:true
                    });
                })

        }


        //查询订单详情列表
        $scope.queryOrderDetail = function (orderId) {
            ajax.get({
                url: "/back/order/orderDetailList",
                data: {
                    orderId: orderId
                }
            }).then(function (result) {
                console.log(result);
                $scope.data.isShowDetail = true;
                $scope.orderDetailList = result;
            });
        }



        //支付完成
        $scope.paySuccess = function (id) {
            ajax.post({
                url: "back/order/finishPay",
                data:{
                    orderId: id
                }
            }).then(function (result) {
                $state.go('admin.linePreOrder', null, {
                    reload: true
                });
            });
        };

        //删除订单
        $scope.del = function(id){
            ajax.post({
                url: 'back/order/delete',
                data:{
                    orderId:id
                }
            }).then(function(){
                Flash.create('success', '删除成功', 'custom-class');
                $state.go('admin.linePreOrder',null,{
                    reload:true
                });
            })
        }
    }])
    .filter('status', function () {
        return function (item) {
            return item == 1 ? '采购完成' : '未采购';
        }
    });